package com.liuwei.msmall.product.controller.web;

import com.alibaba.fastjson.TypeReference;
import com.liuwei.msmall.common.dto.SeckillSkuRedisTo;
import com.liuwei.msmall.common.utils.R;
import com.liuwei.msmall.product.entity.CategoryEntity;
import com.liuwei.msmall.product.feign.SeckillFeginService;
import com.liuwei.msmall.product.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @Classname IndexController
 * @Date 2021/4/7 3:46 下午
 * @Created by llww
 */
@Controller
public class IndexController {

    @Autowired
    CategoryService categoryService;
    @Autowired
    SeckillFeginService seckillFeginService;

    @RequestMapping({"/", "/index"})
    public String index(Model model) {
        long l = System.currentTimeMillis();
        //查出一级分类
        List<CategoryEntity> categoryEntities = categoryService.getCatelogLevel1();
        model.addAttribute("categorys", categoryEntities);
        System.out.println("查询耗时：" + (System.currentTimeMillis() - l));
        //查询秒杀信息
        R res = seckillFeginService.getCurrentSeckillSkuInfo();
        if (res.getCode() == 0){

            List<SeckillSkuRedisTo> seckillData = res.getData("data", new TypeReference<List<SeckillSkuRedisTo>>() {});
            model.addAttribute("seckillData", seckillData);
        }


        return "index";
    }








}
